<?php
namespace backend\models;

use yii\db\ActiveRecord;

class RoomInfo extends ActiveRecord
{
    const ALREADY_RENT_OUT = 1; //已经租出去的状态

    public static function tableName()
    {
        return '{{%room_info}}';
    }
    public static function showHouseInfo($house_info_id)
    {
        return self::find()->where(['house_info_id'=>$house_info_id])->asArray()->all();
    }
    public static function roomCount($house_info_id)
    {
        return self::find()->where(['house_info_id'=>$house_info_id])->count();
    }
    public static function roomAlreadyToken($house_info_id)
    {
        return self::find()->where(['house_info_id'=>$house_info_id,"status"=>self::ALREADY_RENT_OUT])->count();
    }

    /**
     * 创建
     *
     * @access public
     * @param mixed $arg1 参数一的说明
     * @param mixed $mixed 这是一个混合类型
     * @return array 返回类型
     */
    public static function createRoomInfo($data)
    {
        $model = new self();
        $model->setAttributes($data,false);
        if($model->save()) {
            return isset($model->id);
        }else{
            throw new \Exception('插入失败');
        }
    }
}